package jsyf.oa.web.device;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.FastJsonConvert;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.device.DeviceFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by LT on 2018/3/6.
 */
@Api(value = "设备接口", description = "设备接口")
@Controller
@RequestMapping("/device")
public class DeviceController {

    @Resource
    private DeviceFacade deviceFacade;

    /**
     * @description: 设备列表
     * @author: @崔程鵬 @cuichengpeng
     * @creat: 14:09  2018/3/13 0013
     * @since: V1.0.0
     * @see jsyf.oa.web
     */
    @ResponseBody
    @RequestMapping(value = "/getDeviceList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取设备列表",
            notes = "获取设备列表 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{pageSize:2,requestPage=1}", dataType = "String", paramType = "body")
    public void getDeviceList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject results = deviceFacade.getDeviceList(jsonData);
        if (results != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(results));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/add.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "添加品牌",
            notes = "添加品牌 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void add(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(this.deviceFacade.add(jsonData)));
    }

    @ResponseBody
    @RequestMapping(value = "/removeById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过id物理删除设备",
            notes = "通过id物理删除设备 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "id:''", dataType = "String", paramType = "body")
    public void removeById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject obj = new JSONObject();
        obj.put("isOk", this.deviceFacade.removeById(jsonData));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @ResponseBody
    @RequestMapping(value = "/delById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过id逻辑删除设备",
            notes = "通过id逻辑删除设备 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "id:''", dataType = "String", paramType = "body")
    public void delById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject obj = new JSONObject();
        obj.put("isOk", this.deviceFacade.delById(jsonData));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @ResponseBody
    @RequestMapping(value = "/update.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "修改品牌信息",
            notes = "修改品牌信息 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "JSONObject:''", dataType = "String", paramType = "body")
    public void update(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject obj = new JSONObject();
        obj.put("isOk", this.deviceFacade.update(jsonData));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @ResponseBody
    @RequestMapping(value = "/updateDevice.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "修改设备信息",
            notes = "修改设备信息 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{pageSize:2,requestPage=1}", dataType = "String", paramType = "body")
    public void updateDevice(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        Boolean results = deviceFacade.updateDevice(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("bool", results);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @ResponseBody
    @RequestMapping(value = "/saveDevice.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "新建新机入库单",
            notes = "新建新机入库单 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "JSONObject:''", dataType = "String", paramType = "body")
    public void saveDevice(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        Boolean results = deviceFacade.saveDevice(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("bool", results);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));

    }
    /*新建旧机入库单*/
    @ResponseBody
    @RequestMapping(value = "/saveOldCustomer.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "原客户信息",
            notes = "原客户信息 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void saveOldCustomer(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        Boolean results = deviceFacade.saveOldCustomer(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("bool", results);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));

    }
    @ResponseBody
    @RequestMapping(value = "/saveAssess.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "评估置换信息",
            notes = "评估置换信息 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void saveAssess(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        Boolean results = deviceFacade.saveAssess(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("bool", results);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));

    }

    @ResponseBody
    @RequestMapping(value = "/saveSalesCost.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "销售成本",
            notes = "销售成本 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void saveSalesCost(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        Boolean results = deviceFacade.saveSalesCost(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("bool", results);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));

    }
    @ResponseBody
    @RequestMapping(value = "/getDevicePage.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取设备型号列表",
            notes = "获取设备型号列表 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{'deviceTypeName':'1','brandName':'竹内','requestPage':'1','pageSize':'30'}", dataType = "String", paramType = "body")
    public void getDevicePage(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject results = deviceFacade.getDevicePage(jsonData);
        if (results != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(results));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }
    @ResponseBody
    @RequestMapping(value = "/getDeviceById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取设备详细信息",
            notes = "获取设备详细信息 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{'id':'2017121618004C8DBA351757C0A20989'}", dataType = "String", paramType = "body")
    public void getDeviceById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject results = deviceFacade.getDeviceById(jsonData);
        if (results != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(results));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getDeviceByCompanyId.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取设备详细信息",
            notes = "获取设备详细信息 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{'id':'2017121618004C8DBA351757C0A20989'}", dataType = "String", paramType = "body")
    public void getDeviceByCompanyId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> results = deviceFacade.getDeviceByCompanyId(jsonData);
        if (results != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrHourTimeRespond(results));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }



}
